<template>
	<jk-dialog
		:dialog-state="showDialog"
		:title="machine + '-停机详情'"
		width="1200px"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		:show-close-btn="true"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<jk-table
			border
			:height="dialogTableHeight - 30"
			:data="tableData"
		>
			<!-- <vxe-column type="seq" width="60"></vxe-column> -->
			<vxe-column field="typeId" title="停机类型">
				<template slot-scope="scope">
					<!-- <span v-if="scope.row.typeId = 1"><i style="color: rgb(45, 140, 240);" class="vxe-icon-dot"></i>翻改停机</span> -->
					<span v-if="scope.row.typeId = 1">翻改停机</span>
					<span v-else-if="scope.row.typeId = 2">落纱停机</span>
					<span v-else-if="scope.row.typeId = 3">保养停机</span>
					<span v-else>其它停机</span>
				</template>
			</vxe-column>
			<vxe-column field="shutdownState" title="停机状态">
				<template slot-scope="scope">
					<span v-if="scope.row.shutdownState = 0">停机中</span>
					<span v-else>已复机</span>
				</template>
			</vxe-column>
			<vxe-column field="beginTime" width="140" title="停机开始时间"></vxe-column>
			<vxe-column field="endTime" width="140" title="停机结束时间"></vxe-column>
			<vxe-column field="timeSecond" width="120" title="停机时长（秒）"></vxe-column>
			<vxe-column field="spinLength" title="停机纺纱长度"></vxe-column>
			<vxe-column field="productName" title="停机在产品种"></vxe-column>
			<vxe-column field="empName" title="看台人员"></vxe-column>
			<vxe-column field="processName" title="工序"></vxe-column>
			<vxe-column field="workshopName" title="区域"></vxe-column>
		</jk-table>
		<!-- 分页组件 -->
		<footer ref="box2" class="flex-end-center margin-top-10">
			<jk-page
				:page-index="searchParams.pageNo"
				:page-sizes="searchParams.pageSizes"
				:page-size="searchParams.pageSize"
				:total="totalCount"
				@on-change="onPageChange"
			/>
		</footer>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import { productionPrdReportGetProcessDayData } from '../../../api/production/reports';
    import { pageConfig } from '../../../utils/jk/jk-tool';
    import { systemUserColumnConfigGet } from '../../../api/system/column-config';
    import XEUtils from 'xe-utils';
    import { workforcemanagementShiftPage } from '../../../api/schedule/shift';
    import { productionMachineShutdownRecordsMachinePage } from '../../../api/production/reports';
    export default {
        mixins: [calHeight],
        components: {},
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            params: {
                type: Object,
                default() {
                    return {};
                }
            },
            // eslint-disable-next-line vue/require-default-prop
            machine: {
                type: String
            }
        },
        data() {
            return {
                shiftList: [],
                tableLoading: false,
                showDialog: false,
                processList: [],
                tableData: [],
                totalCount: 0,
                searchParams: {
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize
                },
                tableColumnList: [],
                noCalKey: ['machineName', 'productName', 'batchCode']
            };
        },
        methods: {
            onPageChange(e, size) {
                this.$set(this.searchParams, 'pageNo', e);
                this.$set(this.searchParams, 'pageSize', size);
                this.getListRequest();
            },
            footerMethod({ columns, data }) {
                return [
                    columns.map((column, columnIndex) => {
                        if (columnIndex === 0) {
                            return `合计`;
                        }
                        if (!this.noCalKey.includes(column.property)) {
                            return XEUtils.sum(data, column.property);
                        }
                        return null;
                    })
                ];
            },
            onSearchBtn() {
                this.getListRequest();
            },
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
            },
            getMenuColumnListRequest() {
                return systemUserColumnConfigGet({ path: 'processYieldDailyReport', filterShow: true }).then(res => {
                    if (res.data.status === 200) {
                        this.tableColumnList = res.data.res.columnConfigList && res.data.res.columnConfigList.length ? res.data.res.columnConfigList[0].itemList : [];
                    }
                });
            },
            getListRequest() {
                this.tableLoading = true;
                return productionMachineShutdownRecordsMachinePage(this.params).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                        this.totalCount = res.data.count;
                    }
                });
            },
            getShiftListRequest() {
                return workforcemanagementShiftPage({ auditState: 1 }).then(res => {
                    if (res.data.status === 200) {
                        this.shiftList = res.data.res || [];
                        this.$set(this.searchParams, 'shiftId', this.shiftList && this.shiftList.length ? this.shiftList[0].id : null);
                    }
                });
            },
            async getDependentData() {
                this.tableLoading = true;
                await this.getShiftListRequest();
                await this.getMenuColumnListRequest();
                await this.getListRequest();
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.$set(this.searchParams, 'processCode', this.params.processCode);
                    this.$set(this.searchParams, 'belongDate', this.params.belongDate);
                    this.processList = this.$store.state.user.userProcess.processList;
                    this.getDependentData();
                }
            }
        }
    };
</script>
